home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / shadez.swf / scripts / STC9 / System / CProfiler.as < prev   
Text File  |  2011-08-19  |  15KB  |  436 lines

  1. package STC9.System
  2. {
  3.    import STC9.String.CString;
  4.    import flash.system.System;
  5.    import flash.text.TextField;
  6.    import flash.text.TextFieldAutoSize;
  7.    import flash.text.TextFormat;
  8.    import flash.utils.getTimer;
  9.    
  10.    public class CProfiler extends TextField
  11.    {
  12.       
  13.       static var mNumberOfSamples:Number = 30;
  14.       
  15.       private static const mAllowProfiles:Boolean = true;
  16.       
  17.       private static var SLOWEXPIRETIME:uint = 5 * 1000;
  18.       
  19.       private static const mAllowDebugs:Boolean = true;
  20.       
  21.       private static var _this:CProfiler;
  22.        
  23.       
  24.       private var mSamples:Array;
  25.       
  26.       private var mProfiles:Object;
  27.       
  28.       private var mLastTimeStamp:Number;
  29.       
  30.       private var mAlign:String;
  31.       
  32.       private var mDebugs:Object;
  33.       
  34.       public var mMode:String = "normal";
  35.       
  36.       private var mSampleTotalTime:Number;
  37.       
  38.       public var mDebug:String = "";
  39.       
  40.       public function CProfiler(param1:String = "RIGHT", param2:String = "normal")
  41.       {
  42.          mDebug = "";
  43.          mMode = "normal";
  44.          _this = this;
  45.          super();
  46.          mAlign = param1;
  47.          this.defaultTextFormat = new TextFormat("_sans",9,0);
  48.          this.text = "FPS: ";
  49.          this.background = true;
  50.          this.backgroundColor = 15658734;
  51.          this.border = false;
  52.          this.x = 0;
  53.          this.y = 0;
  54.          this.autoSize = TextFieldAutoSize.LEFT;
  55.          mMode = param2;
  56.          Reset();
  57.       }
  58.       
  59.       public static function Show() : void
  60.       {
  61.          _this.visible = true;
  62.       }
  63.       
  64.       public static function StartProfile(param1:String) : void
  65.       {
  66.          var _loc2_:Object = null;
  67.          if(true)
  68.          {
  69.             ┬º┬ºpush(mActive);
  70.             if(true)
  71.             {
  72.                if(!┬º┬ºpop())
  73.                {
  74.                   if(true)
  75.                   {
  76.                      return;
  77.                   }
  78.                }
  79.                else
  80.                {
  81.                   ┬º┬ºpush(mAllowProfiles);
  82.                   if(true)
  83.                   {
  84.                      ┬º┬ºpush(!┬º┬ºpop());
  85.                      if(!┬º┬ºpop())
  86.                      {
  87.                      }
  88.                      addr32:
  89.                      if(┬º┬ºpop())
  90.                      {
  91.                         return;
  92.                      }
  93.                      _loc2_ = !!_this.mProfiles[param1] ? _this.mProfiles[param1] : {
  94.                         "mClear":true,
  95.                         "mSlowTime":0,
  96.                         "mSlowTimeExpires":getTimer() + SLOWEXPIRETIME
  97.                      };
  98.                      ┬º┬ºgoto(addr34);
  99.                   }
  100.                   ┬º┬ºpop();
  101.                   ┬º┬ºgoto(addr32);
  102.                   ┬º┬ºpush(!_this);
  103.                }
  104.                addr34:
  105.                if(true)
  106.                {
  107.                   if(_loc2_.mClear)
  108.                   {
  109.                      if(true)
  110.                      {
  111.                         _loc2_.mTotalTime = 0;
  112.                         if(true)
  113.                         {
  114.                            _loc2_.mClear = false;
  115.                            addr80:
  116.                            _loc2_.mStartTimer = getTimer();
  117.                         }
  118.                         ┬º┬ºgoto(addr80);
  119.                      }
  120.                      _this.mProfiles[param1] = _loc2_;
  121.                      ┬º┬ºgoto(addr96);
  122.                   }
  123.                   ┬º┬ºgoto(addr80);
  124.                }
  125.                addr96:
  126.                return;
  127.             }
  128.             ┬º┬ºgoto(addr32);
  129.          }
  130.          ┬º┬ºgoto(addr39);
  131.       }
  132.       
  133.       public static function Hide() : void
  134.       {
  135.          if(true)
  136.          {
  137.             _this.visible = false;
  138.          }
  139.       }
  140.       
  141.       public static function StopProfile(param1:String, param2:Boolean = false) : Number
  142.       {
  143.          var _loc3_:uint = 0;
  144.          var _loc4_:Object = null;
  145.          if(!mActive)
  146.          {
  147.             return 0;
  148.          }
  149.          if(!mAllowProfiles || !_this || !_this.mProfiles[param1])
  150.          {
  151.             return 0;
  152.          }
  153.          _loc3_ = getTimer();
  154.          (_loc4_ = _this.mProfiles[param1]).mLocalTime = _loc3_ - _loc4_.mStartTimer;
  155.          if(_loc3_ > _loc4_.mSlowTimeExpires)
  156.          {
  157.             _loc4_.mSlowTime = _loc4_.mLocalTime;
  158.             _loc4_.mSlowTimeExpires = _loc3_ + SLOWEXPIRETIME;
  159.          }
  160.          _loc4_.mSlowTime = _loc4_.mLocalTime > _loc4_.mSlowTime ? _loc4_.mLocalTime : _loc4_.mSlowTime;
  161.          _loc4_.mTotalTime = !!param2 ? _loc4_.mTotalTime + _loc4_.mLocalTime : _loc4_.mLocalTime;
  162.          return _loc4_.mLocalTime;
  163.       }
  164.       
  165.       public static function Reset() : void
  166.       {
  167.          if(true)
  168.          {
  169.             _this.mSamples = new Array();
  170.             if(true)
  171.             {
  172.                _this.mSampleTotalTime = 0;
  173.                _this.mProfiles = new Object();
  174.             }
  175.             _this.mDebugs = new Object();
  176.          }
  177.       }
  178.       
  179.       public static function AddDebug(param1:String, param2:String) : void
  180.       {
  181.          if(mActive && _this && mAllowDebugs)
  182.          {
  183.             _this.mDebugs[param1] = param2;
  184.          }
  185.       }
  186.       
  187.       public static function get mActive() : Boolean
  188.       {
  189.          return _this.parent != null;
  190.       }
  191.       
  192.       public static function RemoveDebug(param1:String) : void
  193.       {
  194.          if(true)
  195.          {
  196.             ┬º┬ºpush(Boolean(mActive));
  197.             if(Boolean(mActive))
  198.             {
  199.                ┬º┬ºpop();
  200.                if(true)
  201.                {
  202.                   addr29:
  203.                   if(_this && mAllowDebugs)
  204.                   {
  205.                   }
  206.                   ┬º┬ºgoto(addr47);
  207.                }
  208.                delete _this.mDebugs[param1];
  209.                addr47:
  210.                return;
  211.             }
  212.          }
  213.          ┬º┬ºgoto(addr29);
  214.       }
  215.       
  216.       public static function ToggleMode() : void
  217.       {
  218.          if(true)
  219.          {
  220.             if(_this.mMode == "normal")
  221.             {
  222.                if(true)
  223.                {
  224.                   _this.mMode = "fpsonly";
  225.                   if(false)
  226.                   {
  227.                      addr37:
  228.                   }
  229.                }
  230.             }
  231.             else if(_this.mMode == "fpsonly")
  232.             {
  233.                _this.mMode = "off";
  234.                ┬º┬ºgoto(addr37);
  235.             }
  236.             else
  237.             {
  238.                _this.mMode = "normal";
  239.             }
  240.             ┬º┬ºpush(_this);
  241.             ┬º┬ºpush(_this.mMode == "off");
  242.             if(true)
  243.             {
  244.                ┬º┬ºpush(!┬º┬ºpop());
  245.             }
  246.             ┬º┬ºpop().visible = ┬º┬ºpop();
  247.          }
  248.       }
  249.       
  250.       public static function ToggleVisible() : void
  251.       {
  252.          _this.visible = !_this.visible;
  253.       }
  254.       
  255.       public function Dispose() : void
  256.       {
  257.       }
  258.       
  259.       function Clone() : CProfiler
  260.       {
  261.          return undefined;
  262.       }
  263.       
  264.       private function Pad(param1:String, param2:Number) : String
  265.       {
  266.          while(param1.length < param2)
  267.          {
  268.             param1 = " " + param1;
  269.          }
  270.          return param1;
  271.       }
  272.       
  273.       private function GetFPS(param1:Number) : Number
  274.       {
  275.          var _loc2_:* = undefined;
  276.          _loc2_ = 1;
  277.          return Math.round(1000 / param1 * _loc2_) / _loc2_;
  278.       }
  279.       
  280.       public function Update(param1:Boolean = false) : void
  281.       {
  282.          var _loc2_:Number = NaN;
  283.          var _loc3_:Number = NaN;
  284.          var _loc4_:* = null;
  285.          var _loc5_:Array = null;
  286.          var _loc6_:Object = null;
  287.          if(!mActive)
  288.          {
  289.             return;
  290.          }
  291.          _loc2_ = getTimer();
  292.          if(mLastTimeStamp)
  293.          {
  294.             _loc3_ = _loc2_ - mLastTimeStamp;
  295.             mSampleTotalTime += _loc3_;
  296.             mSamples.push(_loc3_);
  297.             loop0:
  298.             do
  299.             {
  300.                if(mSamples.length > mNumberOfSamples)
  301.                {
  302.                   continue;
  303.                }
  304.                if(true)
  305.                {
  306.                   this.text = "FPS: " + CString.Pad(GetFPS(mSampleTotalTime / mSamples.length),"0",3);
  307.                   if(true)
  308.                   {
  309.                      this.text += " (" + Math.round(System.totalMemory / (1024 * 1024)) + "mb)";
  310.                      if(true)
  311.                      {
  312.                         if(mMode == "normal")
  313.                         {
  314.                            if(true)
  315.                            {
  316.                               _loc5_ = new Array();
  317.                               var _loc7_:* = 0;
  318.                               if(true)
  319.                               {
  320.                                  var _loc8_:* = mProfiles;
  321.                                  if(true)
  322.                                  {
  323.                                     loop1:
  324.                                     while(true)
  325.                                     {
  326.                                        ┬º┬ºpush(┬º┬ºhasnext(_loc8_,_loc7_));
  327.                                        if(true)
  328.                                        {
  329.                                           if(┬º┬ºpop())
  330.                                           {
  331.                                              _loc4_ = ┬º┬ºnextname(_loc7_,_loc8_);
  332.                                              continue;
  333.                                           }
  334.                                           if(true)
  335.                                           {
  336.                                              if(true)
  337.                                              {
  338.                                                 _loc7_ = 0;
  339.                                              }
  340.                                              _loc8_ = mDebugs;
  341.                                              while(true)
  342.                                              {
  343.                                                 ┬º┬ºpush(┬º┬ºhasnext(_loc8_,_loc7_));
  344.                                                 break loop1;
  345.                                              }
  346.                                              addr202:
  347.                                           }
  348.                                           if(_loc5_.length)
  349.                                           {
  350.                                              this.text += "\n-----------------------------------";
  351.                                              _loc5_.sort();
  352.                                              this.text += "\n" + _loc5_.join("\n");
  353.                                              addr227:
  354.                                              mLastTimeStamp = _loc2_;
  355.                                              _loc7_ = mAlign.toUpperCase();
  356.                                              if(true)
  357.                                              {
  358.                                                 if("LEFT" === _loc7_)
  359.                                                 {
  360.                                                    ┬º┬ºpush(0);
  361.                                                    if(true)
  362.                                                    {
  363.                                                    }
  364.                                                 }
  365.                                                 else
  366.                                                 {
  367.                                                    ┬º┬ºpush("RIGHT" === _loc7_ ? 1 : 2);
  368.                                                 }
  369.                                                 switch(┬º┬ºpop())
  370.                                                 {
  371.                                                    case 0:
  372.                                                       x = 0;
  373.                                                       addr235:
  374.                                                       break;
  375.                                                    case 1:
  376.                                                       x = stage.stageWidth - width;
  377.                                                       addr243:
  378.                                                 }
  379.                                                 addr267:
  380.                                                 if(param1)
  381.                                                 {
  382.                                                    addr269:
  383.                                                    for(_loc4_ in mProfiles)
  384.                                                    {
  385.                                                       mProfiles[_loc4_].mClear = true;
  386.                                                    }
  387.                                                    break loop0;
  388.                                                 }
  389.                                                 break loop0;
  390.                                              }
  391.                                              ┬º┬ºgoto(addr261);
  392.                                           }
  393.                                           ┬º┬ºgoto(addr227);
  394.                                        }
  395.                                        break;
  396.                                     }
  397.                                     while(true)
  398.                                     {
  399.                                        if(┬º┬ºpop())
  400.                                        {
  401.                                           _loc4_ = ┬º┬ºnextname(_loc7_,_loc8_);
  402.                                           _loc5_.push(_loc4_ + ":" + mDebugs[_loc4_]);
  403.                                           continue;
  404.                                        }
  405.                                        ┬º┬ºgoto(addr204);
  406.                                     }
  407.                                     addr171:
  408.                                  }
  409.                                  while(true)
  410.                                  {
  411.                                     _loc6_ = mProfiles[_loc4_];
  412.                                     _loc5_.push(_loc4_ + ":" + _loc6_.mLocalTime + (_loc6_.mTotalTime != _loc6_.mLocalTime && _loc6_.mTotalTime != 0 ? " (" + _loc6_.mTotalTime + ")" : " [" + _loc6_.mSlowTime + "]"));
  413.                                     ┬º┬ºgoto(addr171);
  414.                                  }
  415.                               }
  416.                               ┬º┬ºgoto(addr205);
  417.                            }
  418.                            ┬º┬ºgoto(addr235);
  419.                         }
  420.                         ┬º┬ºgoto(addr227);
  421.                      }
  422.                      ┬º┬ºgoto(addr243);
  423.                   }
  424.                   ┬º┬ºgoto(addr267);
  425.                }
  426.                ┬º┬ºgoto(addr269);
  427.             }
  428.             while(mSampleTotalTime -= mSamples.shift(), true);
  429.             
  430.             return;
  431.          }
  432.          ┬º┬ºgoto(addr227);
  433.       }
  434.    }
  435. }
  436.